package com.hxalex.simulationhandle.accessbilityService.receiver.search;

import android.util.Log;
import android.view.accessibility.AccessibilityNodeInfo;

import com.hxalex.simulationhandle.accessbilityService.manger.SearchManger;
import com.hxalex.simulationhandle.accessbilityService.receiver.base.BaseReceiver;

/**
 * Created by hx_Alex on 2018/5/26.
 */

public class UpdateWebSiteReceiver extends BaseReceiver {
    private AccessibilityNodeInfo nodeInfo;
    private boolean isClickOperaMenu = false;

    public UpdateWebSiteReceiver(SearchManger searchManger) {
        super(searchManger);
        FLAG="更新网页命令";
    }

    public AccessibilityNodeInfo getNodeInfo() {
        return nodeInfo;
    }

    public void setNodeInfo(AccessibilityNodeInfo nodeInfo) {
        this.nodeInfo = nodeInfo;
    }


    @Override
    public void doSomething() {
        if(!isPrintCommandMsg)
        {
            Log.w("UpdateWebSiteReceiver","开始执行"+FLAG);
            isPrintCommandMsg=true;
        }
        if(nodeInfo==null) return;
        searchManger.searchOperaMenuButtonInfo(nodeInfo);
        AccessibilityNodeInfo operaMenuButtonInfo = searchManger.getOperaMenuButtonInfo();
        AccessibilityNodeInfo operaReloadButton = searchManger.getOperaReloadButton();
        if (operaMenuButtonInfo != null) {
            if (!isClickOperaMenu ) {
                searchManger.performActionClick(operaMenuButtonInfo);
                isClickOperaMenu = true;
            } else {
                searchManger.searchoperaReloadButtonInfo(nodeInfo);
            }

            if (operaReloadButton != null) {

                boolean b = searchManger.performActionClick(operaReloadButton);
                if (b) {
                    Log.e("updateWebSiteReceiver", "刷新页面结果 reslut:" + b);
                } else {
                    Log.e("updateWebSiteReceiver", "刷新页面失败");
                }
                commandCompleteListener.commandCompleteListener();
                searchManger.setOperaMenuButtonInfo(null);
                searchManger.setOperaReloadButton(null);
            }
        }
    }
}
